package com.sr.maven.dao.impl;

import com.sr.maven.dao.BaseDao;
import com.sr.maven.dao.api.MemorialsDao;
import com.sr.maven.entity.Memorials;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class MemorialsDaoImpl extends BaseDao<Memorials> implements MemorialsDao {
    @Override
    public List<Memorials> selectAllMemorialsDigest() {

        String sql = "SELECT\n" +
                "\tmemorials_id memorialsId,\n" +
                "\tmemorials_title memorialsTitle,\n" +
                "\tconcat(left(memorials_content,10),'...') as memorialsContentDigest,\n" +
                "\tmemorials_content as memorialsContent,\n" +
                "\tmemorials_emp as memorialsEmp,\n" +
                "\temp_name  as memorialsEmpEmpName,\n" +
                "\tmemorials_create_time as memorialsCreateTime,\n" +
                "\tfeedback_time as feedbackTime,\n" +
                "\tfeedback_content as feedbackContent,\n" +
                "\tmemorials_status  as memorialsStatus\n" +
                "FROM\n" +
                "\tt_memorials m\n" +
                "\tleft join t_emp e on m.memorials_emp=e.emp_id";
        return   super.getBeanList(sql,Memorials.class);
    }

    @Override
    public Memorials selectMemorialsById(String memorialsId) {
        String sql = "SELECT\n" +
                "\tmemorials_id memorialsId,\n" +
                "\tmemorials_title memorialsTitle,\n" +
                "\tconcat(left(memorials_content,10),'...') as memorialsContentDigest,\n" +
                "\tmemorials_content as memorialsContent,\n" +
                "\tmemorials_emp as memorialsEmp,\n" +
                "\temp_name  as memorialsEmpEmpName,\n" +
                "\tmemorials_create_time as memorialsCreateTime,\n" +
                "\tfeedback_time as feedbackTime,\n" +
                "\tfeedback_content as feedbackContent,\n" +
                "\tmemorials_status  as memorialsStatus\n" +
                "FROM\n" +
                "\tt_memorials m\n" +
                "\tleft join t_emp e on m.memorials_emp=e.emp_id where m.memorials_id = ?";
        return super.getSingleBean(sql,Memorials.class,memorialsId);
    }

    @Override
    public void updateMemorialsStatus(String memorialsId, int i) {
        String sql = "update t_memorials set memorials_status = ? where memorials_id = ?";
        super.update(sql,i,memorialsId);
    }

    @Override
    public void updateFeedback(String memorialsId, String content) {
        String sql = "update t_memorials set memorials_status = ? ,feedback_content = ?, feedback_time =? where memorials_id = ?";
        String currentTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        super.update(sql,2,content,currentTime,memorialsId);
    }
}
